﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using WpfGraphing.Style;

namespace WpfGraphing.Collections
{
    public class ChartDataList : AbstractViewModel<ChartDataList>
    {
        private ObservableCollection<DataSeries> dataList;

        public ChartDataList()
        {
            dataList = new ObservableCollection<DataSeries>();
        }

        public ObservableCollection<DataSeries> DataList
        {
            get { return dataList; }
            private set { dataList = value;
            OnPropertyChanged("DataList");
            }
        }

        public void AddLines(ChartStyle cs)
        {
            if (cs == null)
            {
                throw new ArgumentNullException(paramName: "cs", message: "Cannot be null");
            }

            int j = 0;
            foreach (DataSeries ds in DataList)
            {
                if (ds.SeriesName == "Default Name")
                {
                    ds.SeriesName = "DataSeries" + j.ToString(CultureInfo.CurrentCulture);
                }
                ds.AddLinePattern();
                for (int i = 0; i < ds.LineSeries.Points.Count; i++)
                {
                    ds.LineSeries.Points[i] = cs.NormalizePoint(ds.LineSeries.Points[i]);
                    ds.Symbols.AddSymbol(cs.ChartCanvas, ds.LineSeries.Points[i]);
                }
                cs.ChartCanvas.Children.Add(ds.LineSeries);
                j++;
            }
        }
    }
}
